#import 
from Constants import *
from Controls import *



'''


'''


class EscapePlayer(object):
	def __init__(self):
		self.image = ESCAPE_IMAGES["player"]
		self.loc = [160,200]

		self.rect = self.image[0].get_rect()
		self.rect.topleft = self.loc

		self.xvel = ESCAPE_PLAYER_DEFAULT_SPD

		#states
		self.correct = False
		self.invincible = False

		#animation variables
		self.flashing = False
		self.frame = 0
		self.frame_wait = ESCAPE_PLAYER_RUN_FRAME_DELAY

	def new_obstacle(self):
		self.correct = False
		self.invincible = False

	def update(self, game):
		#move
		if self.xvel < ESCAPE_PLAYER_DEFAULT_SPD:
			self.xvel += ESCAPE_PLAYER_ACCEL

		self.loc[0] += self.xvel
		self.rect.left = self.loc[0]

		#collide
		if self.correct:
			self.xvel = ESCAPE_PLAYER_DEFAULT_SPD
			if game.question_timer == 0:
				pass#animate
		elif not self.invincible and game.obstacle.active:
			if game.question_timer == 0:
				self.xvel = ESCAPE_PLAYER_MIN_SPD
				self.invincible = True
			elif game.question_timer < ESCAPE_SLOW_DISTANCE:
				self.xvel = ESCAPE_PLAYER_SLOW_SPD

		#animate
		if self.xvel < ESCAPE_PLAYER_SLOW_SPD:
			self.flashing = not self.flashing
		else:
			self.flashing = False

		if 1:#running
			self.frame_wait -= 1
			if self.frame_wait == 0:
				self.frame_wait = ESCAPE_PLAYER_RUN_FRAME_DELAY
				self.frame = (self.frame + 1) % ESCAPE_PLAYER_RUN_FRAMES

		# print self.loc, game.camdisp, game.obstacle.loc

	def draw(self, camsurf, camdisp = (0,0)):
		if not self.flashing:
			camsurf.blit(self.image[self.frame], (self.loc[0] - camdisp[0], self.loc[1] - camdisp[1]))
